﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using WindowsFormsApplication3;

namespace bsy
{
    public partial class MainForm : Form
    {
        private int childFormNumber = 0;
        private Checkstand ck;//收银台
        private Customer cst;//顾客管理
        private Employee ep;//员工管理
        private Card card; //卡管理
        private ReportForm rpf;//报表管理
        private Stock stc;//进货管理
        private Reserve res;//
        private Setup setup;//店铺设置
        private Project project;//项目管理



        public MainForm()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "窗口 " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void mi_checkstand_Click(object sender, EventArgs e)
        {
            if (ck == null || ck.IsDisposed)///判断窗体是否显示
            {
                ck = new Checkstand();
                ck.MdiParent = this;
                ck.Show();
            }
            ck.Focus();
        }

        private void mi_customer_Click(object sender, EventArgs e)
        {
            if (cst == null || cst.IsDisposed)///判断窗体是否显示
            {
                cst = new Customer();
                cst.MdiParent = this;
                cst.Show();
            }
            cst.Focus();
            
        }

        private void mi_employee_Click(object sender, EventArgs e)
        {
           
            if (ep == null || ep.IsDisposed)///判断窗体是否显示
            {
                ep = new Employee();
                ep.MdiParent = this;
                ep.Show();
            }
            ep.Focus();
            
        }

        private void mi_card_Click(object sender, EventArgs e)
        {
            if (card == null || card.IsDisposed)///判断窗体是否显示
            {
                card = new Card();
                card.MdiParent = this;
                card.Show();
            }
            card.Focus();
            
        }


        private void mi_reportform_Click(object sender, EventArgs e)
        {
            if (rpf == null || rpf.IsDisposed)///判断窗体是否显示
            {
                rpf = new ReportForm();
                rpf.MdiParent = this;
                rpf.Show();
            }
            rpf.Focus();
           
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            if (ck == null || ck.IsDisposed)///判断窗体是否显示
            {
                ck = new Checkstand();
                ck.MdiParent = this;
                ck.Show();
            }
            ck.Focus();
        }

        private void mi_syBackup_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定备份数据（之前备份的数据会被删除,可以把D盘的an.bak文件复制到其他地方再备份）？", "系统提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                    string sql = string.Format("backup database bsy to disk='d:\\数据备份（勿删）.bak';");

                    CommonDB.ExecuteSql(sql);

                    MessageBox.Show("备份成功！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception E)
                {
                    MessageBox.Show(E.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private void mi_syrestore_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定还原数据（现在的将被数据覆盖）？", "系统提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                    string sql = string.Format("use master restore database bsy from disk='d:\\数据备份（勿删）.bak' with replace;");
                    CommonDB.ExecuteSql(sql);

                    MessageBox.Show("还原成功！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception E)
                {
                    MessageBox.Show("备份文件不存在或数据库错误！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void mic_Stock_Click(object sender, EventArgs e)
        {
            if (stc == null || stc.IsDisposed)///判断窗体是否显示
            {
                stc = new Stock();
                stc.MdiParent = this;
                stc.Show();
            }
            stc.Focus();
            
        }

        private void mic_reserve_Click(object sender, EventArgs e)
        {
            if (res == null || res.IsDisposed)///判断窗体是否显示
            {
                res = new Reserve();
                res.MdiParent = this;
                res.Show();
            }
            res.Focus();
        }

        private void mi_sysetup_Click(object sender, EventArgs e)
        {
            if (setup == null || setup.IsDisposed)///判断窗体是否显示
            {
                setup = new Setup();
                setup.MdiParent = this;
                setup.Show();
            }
            setup.Focus();
            
        }

        private void project_menu_Click(object sender, EventArgs e)
        {
            if (project == null || project.IsDisposed)///判断窗体是否显示
            {
                project = new Project();
                project.MdiParent = this;
                project.Show();
            }
            project.Focus();
        }
    }
}
